<?php
define('QAPP', 1);
if (!file_exists("../config.php")) {
    exit();
}
if (!file_exists('../config.php'))exit();
include('../config.php');
include('../../core/config.php');

//文件保存目录路径(系统真是路径)
$save_path = PublicRoot . UploadDir . '/';

//相对站点的路径
$save_url = SystemDir . UploadDir . '/';

//alert(str_replace('Public/Js/kindeditor/php/','',dirname($_SERVER['PHP_SELF']) . '/Uploads/'));
if ((isset($_POST['img'])) && (!empty($_POST['img']))) {
    $img = $_POST['img'];
    //set_time_limit(0);
    $ymd = date("Ymd");
    $save_path .= $ymd . '/';
    $save_url .= $ymd . '/';
    if (!file_exists($save_path)) {
        @mkdir($save_path, 0777);
    }
    $filename = getCuid() . '.png';
    $save_path .= $filename;
    $save_url .= $filename;

    if (isset($_POST['isurl'])) {
        if (http_downfile($img, $save_path)) {
            echo $save_url;
        } else {
            echo "";
        }
    } else {
        $base64_body = substr(strstr($img, ','), 1);
        $data = base64_decode($base64_body);
        file_put_contents($save_path, $data);
        echo $save_url;
    }
} else {
    echo '';
}